#include "EndReciteTaskDialog.h"

EndReciteTaskDialog::EndReciteTaskDialog(QDialog *parent)
    : QDialog(parent),
    mSelectedTask(ST_None)
{
	ui.setupUi(this);

	QString text = QString(tr("This test is finished."));
	text.append(QString("\n"));
	text.append(QString(tr("Do you want to continue this test?")));
	text.append(QString("\n"));
	text.append(QString(tr("Or start a new one?")));
	ui.textLabel->setText(text);
	ui.textLabel->setAlignment(Qt::AlignHCenter | Qt::AlignJustify);
	QFont font;
	font.setPointSize(16);
	ui.textLabel->setFont(font);
	this->setWindowTitle(QString(tr("End of test")));
	this->setWindowFlags(Qt::WindowStaysOnTopHint);
	ui.cancelButton->setIcon(QIcon("./pixmaps/cancel-256.png"));
	ui.analyseDataButton->setIcon(QIcon("./pixmaps/kchart.png"));
	ui.selectListButton->setIcon(QIcon("./pixmaps/fileopen-256.png"));
	ui.endTestButton->setIcon(QIcon("./pixmaps/player_stop-256.png"));

	QObject::connect(ui.cancelButton, SIGNAL(clicked()), this, SLOT(cancelButtonClicked()));
	QObject::connect(ui.endTestButton, SIGNAL(clicked()), this, SLOT(endTestButtonClicked()));
	QObject::connect(ui.selectListButton, SIGNAL(clicked()), this, SLOT(selectListButtonClicked()));
	QObject::connect(ui.analyseDataButton, SIGNAL(clicked()), this, SLOT(analyseDataButtonClicked()));
}

EndReciteTaskDialog::~EndReciteTaskDialog()
{

}

void EndReciteTaskDialog::paintEvent ( QPaintEvent * event )
{
	//cout<<"EndReciteTaskDialog::paintEvent"<<endl;
	QImage pixmap(QString("./pixmaps/dialog-information.png"));
	//if (pixmap.isNull())
	//	cout<<"EndReciteTaskDialog::showThisDialog-->pixmap is null."<<endl;
	//QRectF target = ui.iconWidget->geometry();
	QRect target = QRect(0, 0, ui.iconWidget->geometry().width(), ui.iconWidget->geometry().height());
	pixmap = pixmap.scaled(QSize(target.width(), target.height()), Qt::KeepAspectRatio);
	int tcx = target.x() + target.width()/2;
	int tcy = target.y() + target.height()/2;
	//QRect source = QRect(0, 0, pixmap.width(), pixmap.height());
	//QPoint targetPoint = QPointF(target);
	QPainter painter(this);
	//painter.setRenderHints(QPainter::Antialiasing | QPainter::SmoothPixmapTransform | QPainter::HighQualityAntialiasing);
	painter.drawImage(tcx - pixmap.width()/2, tcy - pixmap.height()/2, pixmap);
	//painter.drawPixmap(0, 0, pixmap);
}

SelectedTask EndReciteTaskDialog::showThisDialog()
{

	//this->update();

	/*int height = this->geometry().height();
	height /= 2;
	QRect iconRect = ui.iconWidget->geometry();
	iconRect.setHeight(height);
	ui.iconWidget->setGeometry(iconRect);*/


	SelectedTask result = SelectedTask(this->exec());
	return result;
}

void EndReciteTaskDialog::cancelButtonClicked()
{
	mSelectedTask = ST_None;
	this->done(int(mSelectedTask));
}

void EndReciteTaskDialog::endTestButtonClicked()
{
	mSelectedTask = ST_End;
	this->done(int(mSelectedTask));
}

void EndReciteTaskDialog::selectListButtonClicked()
{
	mSelectedTask = ST_OpenList;
	this->done(int(mSelectedTask));
}

void EndReciteTaskDialog::analyseDataButtonClicked()
{
	mSelectedTask = ST_Analyse;
	this->done(int(mSelectedTask));
}

/*void EndReciteTaskDialog::showThisDialog()
{

}*/
